home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / CRT.SWG / 0007_Check KEYPRESS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  98 lines

  1. {
  2. To the person that posted the message about using KeyPressed or anyone
  3. else interested. Below is a Function that I have used to read keyboard input
  4. that is similiar to KeyPressed.  It does a KeyPressed and ReadKey all in one
  5. statement.  If you are familiar With BASIC this InKey Function is similiar
  6. to the one in BASIC in that is doesn't sit and wait For input.  The KeyEnh
  7. Function just returns True/False depending on whether or not it detected
  8. an Enhanced keyboard. SHIFT, CTRL, and ALT are global Boolean Variables
  9. which value reflect the state of these keys involved in the the keypress.
  10. }
  11.  
  12. Uses
  13.   Dos;
  14.  
  15. Function KeyEnh:  Boolean;
  16. Var
  17.   Enh:  Byte Absolute $0040:$0096;
  18.  
  19. begin
  20.   KeyEnh := False;
  21.   if (Enh and $10) = $10 then
  22.     KeyEnh := True;
  23. end;
  24.  
  25. Function InKey(Var SCAN, ASCII:  Byte): Boolean;
  26. Var
  27.   i     :  Integer;
  28.   Shift,
  29.   Ctrl,
  30.   Alt   : Boolean;
  31.   Temp,
  32.   Flag1 : Byte;
  33.   HEXCH,
  34.   HEXRD,
  35.   HEXFL : Byte;
  36.   reg   : Registers;
  37.  
  38. begin
  39.   if KeyEnh then
  40.   begin
  41.     HEXCH := $11;
  42.     HEXRD := $10;
  43.     HEXFL := $12;
  44.   end
  45.   else
  46.   begin
  47.     HEXCH := $01;
  48.     HEXRD := $00;
  49.     HEXFL := $02;
  50.   end;
  51.  
  52.   reg.ah := HEXCH;
  53.   Intr($16, reg);
  54.   i := reg.flags and FZero;
  55.  
  56.   reg.ah := HEXFL;
  57.   Intr($16, reg);
  58.   Flag1 := Reg.al;
  59.   Temp  := Flag1 and $03;
  60.  
  61.   if Temp = 0 then
  62.     SHIFT := False
  63.   ELSE
  64.     SHIFT := True;
  65.  
  66.   Temp  := Flag1 and $04;
  67.   if Temp = 0 then
  68.     CTRL := False
  69.   ELSE
  70.     CTRL := True;
  71.  
  72.   Temp  := Flag1 and $08;
  73.   if Temp = 0 Then
  74.     ALT  := False
  75.   ELSE
  76.     ALT  := True;
  77.  
  78.   if i = 0 then
  79.   begin
  80.     reg.ah := HEXRD;
  81.     Intr($16, reg);
  82.     scan  := reg.ah;
  83.     ascii := reg.al;
  84.     InKey := True;
  85.   end
  86.   else
  87.     InKey := False;
  88. end;
  89.  
  90.  
  91. Var
  92.   Hi, Hi2 : Byte;
  93.  
  94. begin
  95.   Repeat Until InKey(Hi,Hi2);
  96.   Writeln(Hi);
  97.   Writeln(Hi2);
  98. end.